from lib.ZImage import ZImage
from lib.ZLoadJson import ZLoadJson
from resource.script.Eve.res.glo import _e_src


class Eve ( object ) :
	def __init__ ( self , father , id ) :
		super ( Eve , self ).__init__ ( )
		self.father = father
		self.data = ZLoadJson ( _e_src [ 'data' ] [ 'block' ] [ id ] )
		self._running = False
		self.image = ZImage ( self , self.data.get ( ) [ 'big-icon' ] , [ 55 , 55 ] )
		self.rect = self.image.rect
		self.screen = self.father.screen
		self.type = self.data.get ( ) [ 'type' ]
		self.effect = int ( self.data.get ( ) [ 'effect' ] )
		self._pos = 10 , 10
		self._used = False

	def draw ( self ) :
		if self._running and not self._used :
			if self.type == 0 :
				from resource.ui.sces import players
				players [ 0 ]._add_hp ( self.effect )
				self._used = True
			elif self.type == 1 :
				from resource.ui.sces import players
				players [ 0 ]._add_dd ( self.effect )
				self._used = True
			elif self.type == 2 :
				from resource.ui.sces import players
				players [ 0 ]._add_mp ( self.effect )
				self._used = True
		self.image.draw ( )

	@property
	def _pos ( self ) :
		return self.rect.topleft

	@_pos.getter
	def _pos ( self ) :
		return self.rect.topleft

	@_pos.setter
	def _pos ( self , pos ) :
		self.rect.topleft = map ( lambda (a , b ) : a + b , zip ( self.father._pos , pos ) )
